<template>
	<view class="article_page clearfix">

		<scroll-view class="top" v-if="tableList.length>0" scroll-x="true">
			<!-- tab -->
			<view class="tab">
				<view class="tab_nav" style='font-size:12px'>
					<view class="setTab" v-for="(item, index) in tableList" :key="item.id" :data-index="index"
						:data-sortb="item.sortStatus" :class=" tableIndex == index ? 'active' : ''" :data-id="item.id"
						@click="ontabtap">
						{{item.columnName}}
					</view>
				</view>
			</view>
		</scroll-view>
		<!--end  top-->

		<view class="con_wrap">
			<view class="item clearfix" :class="[item.hotStatus ? 'ishot':'nohot']" v-for="item in contentList"
				:key="item.id" @click="goDetail(item.id)">
				<view class="title">{{item.title}}</view>
				<view class="img_wrap">
					<image class="img" :src="item.img" mode="aspectFill"></image>
				</view>
				<!-- <view class="remark" v-if="isHot || item.hotStatus">
					{{item.remark}}
				</view> -->
				<view class="bottom">
					<view class="b_left">
						<uni-icons type="eye" color="#999999"></uni-icons>
						<text class="lookNum">{{item.lookNum}}</text>
					</view>
					<view class="b_right">
						<text class="day">{{item.day}}天前</text>
					</view>
				</view>
			</view>
		</view>
		<!-- <uni-load-more :status="status" v-if="pageSize > 1" /> -->
		<no-data v-if="isfish"></no-data>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tableList: [],
				colunmId: 0,
				tableIndex: 0,
				contentList: [],
				sortStatus: null,
				pageNo: 1,
				pageSize: 0,
				status: 'more',
				isLoading:false,
				isfish:false,
			}
		},
		onLoad() {
			//获取栏目
			this.getSchoolColumn();
		},
		onShow() {
			if (this.columnId) {
				this.pageNo=1;
				this.contentList=[];
				this.getList();
			}
		},
		computed: {
			isHot: function() {
				return this.sortStatus == 1 ? true : false;
			}
		},
		//底部加载更多
		onReachBottom() {
			// let that = this;
			// let query = {};
			// let pageNo = this.pageNo + 1;
			// query.id = this.columnId;
			// if (pageNo <= this.pageSize) {
			// 	query.pageNo = pageNo;
			// 	that.getMoreData(query)
			// } else {
			// 	that.status = "noMore"
			// }
			!this.isLoading && !this.isfish && this.getList();
		},

		methods: {
			//栏目点击事件
			ontabtap(e) {
				let that = this;
				let index = e.target.dataset.index || e.currentTarget.dataset.index;
				let columnId = e.target.dataset.id || e.currentTarget.dataset.id;
				let sortStatus = e.target.dataset.sortb || e.currentTarget.dataset.sortb;
				if (that.tableIndex !== index) {
					that.sortStatus = sortStatus;
					that.columnId = columnId;
					that.tableIndex = index;
					that.pageNo=1;
					that.contentList = [];
					that.getList();
				}
			},
			//查看详细
			goDetail(obj) {
				uni.navigateTo({
					url: '/pages/article/article_detail?id=' + obj
				});
			},
			//获取栏目
			getSchoolColumn() {
				this.$api.getSchoolColumn().then(res => {
					this.tableList = res.data.data;
					this.sortStatus = res.data.data[0].sortStatus;
					this.columnId = res.data.data[0].id;
					this.getList();
				})
			},
			//根据条件查询列表
			getList() {
				this.isLoading=true;
				console.log(this.columnId)
				this.$api.getSchoolList({id:this.columnId,pageNo:this.pageNo}).then(res => {
					++this.pageNo;
					this.isLoading=false;
					this.isfish=!res.data.data.records.length;
					this.contentList = this.contentList.concat(res.data.data.records);
					// this.pageSize = res.data.data.pages;
				})
			},
			//获取更多数据
			getMoreData(param) {
				this.$api.getSchoolList(param).then(res => {
					let data = res.data.data.records;
					if (data) {
						this.contentList = this.contentList.concat(data);
						this.pageSize = res.data.data.pages;
						this.pageNo = res.data.data.current;
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.top {
		width: 100%;
		white-space: nowrap;
		position: fixed;
		top: var(--window-top);
		z-index: 99;
		left: 0;
		background: $dtg-color-primary;

		/deep/.uni-scroll-view {
			border-radius: 20rpx 20rpx 0 0;
			background: #FFFFFF;
		}

		/deep/.uni-scroll-view::-webkit-scrollbar {
			display: none
		}

		.tab {
			display: flex;
			flex-direction: column;
			border-radius: 20rpx 20rpx 0 0;
		}

		.tab_nav {
			height: 80rpx;
			background: #fff;
			display: flex;
			line-height: 79rpx;
			position: relative;
			color: #999999;
			font-size: 28rpx;
		}

		.setTab {
			min-width: 20%;
			max-width: 20%;
			text-align: center;
			height: 80rpx;
			background-color: white;
			font-size: 26rpx;
			position: relative;
		}

		.active {
			color: black;
			font-size: 15px;
			font-weight: bold;
		}

		.active::after {
			content: "";
			width: 40rpx;
			height: 4rpx;
			background: $dtg-color-primary;
			border-radius: 4rpx;
			margin: -4rpx auto;
			display: block;
			animation: roll .23s linear;
		}

		@keyframes roll {
			0% {
				width: 0;
			}

			100% {
				width: 40rpx;
			}
		}

		.con {
			overflow: hidden;
		}
	}

	.con_wrap {
		width: 690rpx;
		margin: 100rpx auto 0;
		padding-bottom: 40rpx;

		.item {
			margin-bottom: 20rpx;
			width: 100%;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 20rpx;

			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;
				line-height: 32rpx;
			}

			.remark {
				font-size: 28rpx;
				font-weight: 500;
				color: #333333;
				margin-top: 20rpx;
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 10rpx;
			}

			.lookNum {
				margin-left: 10rpx;
				font-size: 24rpx;
				color: #999999;
			}

			.day {
				font-size: 24rpx;
				color: #999999;
			}
		}

		.ishot {
			.title {
				margin-bottom: 20rpx;
			}

			.img_wrap {
				width: 100%;
				height: 300rpx;
				border-radius: 20rpx;
				overflow: hidden;
			}

			.img {
				width: 100%;
				height: 300rpx;
			}

		}

		.nohot {
			.title {
				float: left;
				width: calc(100% - 260rpx);
				height: 100rpx;
				text-overflow: -o-ellipsis-lastline;
				line-height: 50rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				line-clamp: 2;
				-webkit-box-orient: vertical;
			}

			.img_wrap {
				width: 230rpx;
				height: 150rpx;
				border-radius: 20rpx;
				overflow: hidden;
				float: right;
			}

			.img {
				width: 100%;
				height: 150rpx;
			}

			.bottom {
				float: left;
				width: calc(100% - 260rpx);
			}
		}
	}
</style>
<style>
	page {
		background: #F8F8F8;
	}
</style>
